﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qianli.DirSir.Common;
using Qianli.DirSir.Model;
using System.Data.SqlClient;
using System.Data;
namespace Qianli.DirSir.DAL
{
    public class FORMDHLUPSInfoDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 显示快递匹配
        /// </summary>
        /// <returns></returns>
        public List<FORMDHLUPSInfo> FORMDHLUPSInfoShow(int did)
        {
            string sql = "select c.CityName from FORMDHLUPSInfo f join CityInfo c on f.CityID=c.CityID where DHLUPSFEDEXEMSID=" + did + "";
            DataTable table = helper.ExecDataTable(sql);
            List<FORMDHLUPSInfo> list = new List<FORMDHLUPSInfo>();
            foreach (DataRow item in table.Rows)
            {
                FORMDHLUPSInfo f = new FORMDHLUPSInfo();
                
                f.CityName = item["CityName"].ToString();
                
                list.Add(f);
            }
            return list;
        }
        /// <summary>
        /// 快递匹配删除
        /// </summary>
        /// <param name="fdid"></param>
        /// <returns></returns>
        public int FORMDHLUPSInfodDelete(int fdid)
        {
            string sql = "delete  from FORMDHLUPSInfo where DHLUPSFEDEXID="+fdid+"";
            return helper.ExecNonquery(sql);
        }
        /// <summary>
        /// 获取快递名称
        /// </summary>
        /// <returns></returns>
        public List<DHLUPSFEDEXEMSInfo> kuaidiname()
        {
            string sql = "select DHLUPSFEDEXEMSID, DHLUPSFEDEXEMSName from DHLUPSFEDEXEMSInfo";
            DataTable table = helper.ExecDataTable(sql);
            List<DHLUPSFEDEXEMSInfo> list = new List<DHLUPSFEDEXEMSInfo>();
            foreach (DataRow item in table.Rows)
            {
                DHLUPSFEDEXEMSInfo f = new DHLUPSFEDEXEMSInfo();
                f.DHLUPSFEDEXEMSID = Convert.ToInt32(item["DHLUPSFEDEXEMSID"]);
                f.DHLUPSFEDEXEMSName = item["DHLUPSFEDEXEMSName"].ToString();
                list.Add(f);
            }
            return list;
        }
        /// <summary>
        /// 根据id获取城市
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public List<CityInfo> GetidCity(int pid)
        {
            string sql = "select CityID,CityName from CityInfo where ProviceID=" + pid + "";
            DataTable table = helper.ExecDataTable(sql);
            List<CityInfo> list = new List<CityInfo>();
            foreach (DataRow item in table.Rows)
            {
                CityInfo c = new CityInfo();
                c.CityID = Convert.ToInt32(item["CityID"]);
                c.CityName = item["CityName"].ToString();
                list.Add(c);
            }
            return list;
        }
        /// <summary>
        /// 根据快递编号获取城市编号
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        public List<FORMDHLUPSInfo> FORMDHLUPSInfoGetid(int rid)
        {
            string sql = "select CityID from FORMDHLUPSInfo where DHLUPSFEDEXEMSID=" + rid + "";
            DataTable table = helper.ExecDataTable(sql);
            List<FORMDHLUPSInfo> list = new List<FORMDHLUPSInfo>();
            foreach (DataRow item in table.Rows)
            {
                FORMDHLUPSInfo f = new FORMDHLUPSInfo();
                f.CityID = Convert.ToInt32(item["CityID"]);
                list.Add(f);
            }
            return list;
        }
        /// <summary>
        /// 快递匹配添加
        /// </summary>
        /// <param name="rid"></param>
        /// <param name="oid"></param>
        /// <returns></returns>
        public int FORMDHLUPSInfoAdd(int rid, string oid)
        {
            string sql = "insert into FORMDHLUPSInfo(DHLUPSFEDEXEMSID,CityID) values(" + rid + "," + oid + ")";
            return helper.ExecNonquery(sql);
        }
        /// <summary>
        /// 根据快递id删除所有的有关城市
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int kuaidisahnchu(int did)
        {
            string sql = "delete  from FORMDHLUPSInfo where DHLUPSFEDEXEMSID=" + did + "";
            return helper.ExecNonquery(sql);
        }
    }
}
